<script src="{{ getAssets }}js/amazeui.datatables.min.js?v={{ assets_version }}"></script>
<script>
    var curing;
    var tables = $('#dataTables').DataTable({
        "sAjaxSource": location.href
        , "bLengthChange": false
        , "fnServerData": function (sSource, aoData, fnCallback) {
            var queryParams = checkQueryTableData(aoData);
            $.post(sSource, JSON.stringify(queryParams), function (resp) {
                if (resp.aaData.curing) {
                    curing = resp.aaData.curing;
                    $('#curing_name').html(curing.Name);
                    $('#curing_type').html(curing.CuringType == 1 ? '重点养护' : '临时养护');
                    $('#time_limit').html(curing.TimeLimit + '天');
                    $('#product_typeid').html(curing.ProductTypeid == 20 ? '隐形眼镜' : '护理产品');
                    $('#brand_name').html(curing.BrandName);
                    $('#need_check_number').html(curing.NeedCheckNumber);
                    $('#curing_id').val(curing.Id);
                }
                var pageData = {
                    'aaData': resp.aaData.curing_data,
                    'iTotalDisplayRecords': resp.iTotalDisplayRecords,
                    'iTotalRecords': resp.iTotalRecords
                };
                fnCallback(pageData);
            }, 'json')
        }
        , order: []
        , columns: [
            {
                "bSortable": false, render: function (data, type, full, meta) {
                    return productTypeidName(full.Products.TypeId);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.BrandName;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Name;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.ColourNumber;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Spec;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.CastAway;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.ShelfLife;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Products.Unit;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Inventory.Snd.sph;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.Inventory.Snd.cyl;
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return timetransDate(full.manufacture_date);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return timetransDate(full.expiry_date);
                }
            }
            , {
                "bSortable": false, render: function (data, type, full, meta) {
                    return full.lot_number + '<input type="hidden" name="curing_data_id[]" value="' + full.Id + '">';
                }
            }
        ]
        , "aLengthMenu": [20, 50, 100, 200]
		,'bLengthChange': true
        , "serverSide": true
        , "bPaginate": true
        , "bFilter": false	//是否启动过滤、搜索功能
        , "bInfo": true //是否显示页脚信息，DataTables插件左下角显示记录数
        , "bProcessing": true //DataTables载入数据时，是否显示‘进度’提示
    });

    $("#formDoSubmitDialogMy").validator({
        submit: function () {
            if (this.isFormValid()) {
                var that = $("#formDoSubmitDialogMy");
                var submitBtn = that.find('button[type="submit"]');
                if (submitBtn.hasClass('am-disabled')) {
                    return false;
                }
                submitBtn.addClass('am-disabled');
                $.ajax({
                    url: '{{ urlfor "CuringController.CuringProductCheckSave" }}'
                    , type: 'post'
                    , data: that.serialize()
                    , dataType: 'json'
                    , success: function (res) {
                        if (res.code === 0) {
                            location = '{{ urlfor "CuringController.PlanList" }}';
                        } else {
                            layer.alert(res.msg);
                            submitBtn.removeClass('am-disabled');
                        }
                    }
                    , error: function (error) {
                        submitBtn.removeClass('am-disabled');
                        layer.msg('数据提交失败！');
                    }
                });
            }
            return false;
        }
    });
</script>
